package com.zzptc.gyc.gfc;
import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class SeconFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
            View view = inflater.inflate(R.layout.fragment_secon, container, false);
        BarChart bar =view.findViewById(R.id.barChart);
         List<BarEntry> barList=new ArrayList<>();
        List<BarEntry> mBarList=new ArrayList<>();
            for (int i = 0; i < 5; i++) {
            barList.add(new BarEntry(i,new Random().nextInt(20)));
                mBarList.add(new BarEntry(i,new Random().nextInt(25)));
        }
         BarDataSet barDataSet=new BarDataSet(barList,"男");
            barDataSet.setColor(Color.RED);
         BarDataSet barDataSet1=new BarDataSet(mBarList,"女");
         barDataSet1.setColor(Color.BLUE);
        BarData barData=new BarData(barDataSet);
        barData.addDataSet(barDataSet1);
         bar.setData(barData);
         bar.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
         bar.getAxisRight().setEnabled(false);
        barData.setBarWidth(0.2f);
         bar.groupBars(1,0.6f,0);
         bar.getXAxis().setAxisMaximum(6);
         bar.getXAxis().setAxisMinimum(1);
         bar.getXAxis().setLabelCount(5,false);
         bar.getXAxis().setCenterAxisLabels(true);
         return view;
    }


}
